package 力扣日常刷题.木23一月.第04天304;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/3/4
 * @description
 */
public class Demo41零钱兑换 {

    public int coinChange(int[] coins,int amount) {
        int max  = amount + 1;
        int[] dp = new int[amount + 1];
        Arrays.fill(dp,max);
        dp[0] = 0;

        for (int i = 1; i <= amount ; i++) {
            for (int j = 0; j < coins.length; j++) {
                if(coins[j] <= i){
                    dp[i] = Math.min(dp[i],dp[i-coins[j]] + 1);
                }
            }
        }
        return dp[amount] > amount ? -1 :dp[amount];
    }

}
